package com.lhn.bbs.interceptor;/*
 * Description:
 * User:Hello，Mr.Zhou
 * Date:2021-01-13
 * Time:9:39
 *
 * */

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器
@Slf4j
public class JwtInterceptor implements HandlerInterceptor {
    //事前处理(进入接口方法前)
   /* @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String requestURI = request.getRequestURI();
        log.info("============请求地址"+requestURI);
        String token = request.getHeader("token");
        log.info("=============token"+token);
        *//*if (handler instanceof HandlerMethod){
            HandlerMethod hm = (HandlerMethod) handler;
            //获取拦截方法
            Method method = hm.getMethod();
            JwtAnnotation annotation = method.getAnnotation(JwtAnnotation.class);
            if (annotation!=null){//方法含有指定的注解,需要验证token
                boolean checkToken = JwtUtils.checkToken(token);
                if (checkToken){
                    return true;
                }else{
                    ActionResult actionResult = new ActionResult(403,"token fail",null);
                    String json = new Gson().toJson(actionResult);
                    PrintWriter out = response.getWriter();
                    response.setHeader("contentType","application/json");
                    out.write(json);
                    return false;
                }
            }else{
                return true;
            }
        }else{
            return true;
        }*//*
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }*/
}
